package com.jhx.mall.app.servlet;

import com.jhx.mall.app.service.DtsFootprintService;
import com.jhx.mall.app.service.impl.DtsFootprintServiceImpl;
import com.jhx.mall.entity.DtsCategory;
import com.jhx.mall.util.BaseServlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DtsFootprint", value = "/api/user/newFootprint")
public class DtsFootprintServlet extends BaseServlet {
    private DtsFootprintService dtsFootprintService;

    public void init() throws ServletException {
        dtsFootprintService = new DtsFootprintServiceImpl();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String opr=request.getParameter("opr");
        if(opr.equals("insert")){
            Long userId= Long.parseLong(request.getParameter("userId"));
            Long goodsId= Long.parseLong(request.getParameter("goodsId"));
            int rs=dtsFootprintService.insertFootprint(userId,goodsId);
            if(rs!=0){
                ok(request,response,rs);
            }else {
                error(request,response,rs);
            }
        }
    }
}